package com.aaa.controller.tables;

import com.aaa.dao.ApplyDateDao;
import com.aaa.dao.BookDao;
import com.aaa.dao.InventoryMapper;
import com.wsc.entity.AaplyDate;
import com.wsc.entity.FOrderp;
import com.wsc.entity.Inventory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("inventory")
public class InventoryController {
    @Resource
    InventoryMapper inventoryMapper;
    @Resource
    BookDao bookDao;
    @Resource
    ApplyDateDao applyDateDao;
    @RequestMapping("select")
    public Object select(){
        return inventoryMapper.selectList(null);
    }
    @RequestMapping("insert")
    public Integer insert(Inventory inventory){
        return inventoryMapper.insert(inventory);
    }
    @RequestMapping("delete")
    public Integer delete(Integer id){
        return inventoryMapper.deleteById(id);
    }
    @RequestMapping("update")
    public Integer update(Inventory inventory){
        return inventoryMapper.updateById(inventory);
    }
    @RequestMapping("selectAll")
    public Object selectAll(){
        System.out.println(bookDao.select4()+"这是查询全部x");
        return bookDao.select4();
    }
    @RequestMapping("update1")
    public Integer update1(AaplyDate aaplyDate){
        Inventory inventory=new Inventory();
        Integer realityAmount=aaplyDate.getRealityamount();//采购数量
        Integer amount=aaplyDate.getAmount();//入库数量
        Integer inferior=realityAmount-amount;//次品
        inventory.setInferior(inferior);
        inventory.setBook(aaplyDate.getBook());
        inventory.setSurplus(aaplyDate.getAmount());
        return applyDateDao.update1(inventory);
    }
    @RequestMapping("update2")
    public Integer update2(FOrderp fOrderp){
        Inventory inventory=new Inventory();
        inventory.setSurplus(fOrderp.getNum());
        inventory.setBook(fOrderp.getBook());
        return applyDateDao.update2(inventory);
    }

}
